<html>
<body>

<form method= "GET"  action="query.php">
<textarea name="query" cols="60" rows="8"></textarea>
<input type = "submit" value="Submit" />
</form>

<?php
$db_connection = mysql_connect("localhost", "cs143", "");
mysql_select_db("CS143", $db_connection);
$query = $_GET["query"];
$rs = mysql_query($query);

if ($query != "")
{
	print "<table border = '1'>\n";
	print "<tr>";
	$numF = mysql_num_fields($rs);
	//print $numF;
	for($i = 0; $i < $numF; $i++)					// prints the schema names of the table
	{
		$fName = mysql_field_name($rs,$i);
		print "<td> $fName </td>";
	}
	print "</tr>";
	
	
	while($row = mysql_fetch_row($rs)) 
	{
		$arraysize = count($row);
		print "<tr>";
		for($i = 0; $i < $arraysize; $i++)
		{
			print "<td>$row[$i]</td>";
		}
		print "</tr>";

    // print "$sid, $name, $email<br />";
	}
	print "</table>";	
}

mysql_close($db_connection);

?>

</body>
</html>